import React, { Component } from 'react'
import { Button, Tooltip } from 'antd'
import '../../less/index.less'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { convertContent } from '../../constant/lang-util'
import { FormattedMessage } from 'react-intl'

class ReferenceButtonGroup extends Component {
  isDisabled () {
    const {review, isTutor} = this.props
    return !((review.status && review.status !== '已提交') || isTutor)
  }
  getAnswerFile () {
    const {settings, quizDefinition} = this.props || {}

    const url = `${settings.quizWebUrl}/api/simpleCodingQuizzes/${quizDefinition.id}/answerFile`
    window.location.assign(url)
  }
  render () {
    const {quizDefinition} = this.props

    return (<div>
      {quizDefinition.answerPath
              ? <Tooltip title={convertContent('完成作业才能看呦')}>
                <Button disabled={this.isDisabled()} onClick={this.getAnswerFile.bind(this)}>
                  <FormattedMessage id='参考答案' /></Button>
              </Tooltip> : ''
          }
    </div>
    )
  }
}
const mapStateToProps = (state) => ({
  settings: state.settings
})

export default withRouter(connect(mapStateToProps, null)(ReferenceButtonGroup))
